package com.njym.java.security.app.rpc.service;


import com.njym.java.security.api.vo.user.AppUserInfo;
import com.njym.java.security.app.biz.FamilyUserBiz;
import com.njym.java.security.app.entity.FamilyUser;
import com.njym.java.security.auth.client.jwt.UserAuthUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;


/**
 * Created by ace on 2017/9/12.
 */
@Service
public class PermissionService {
    /**
     * userBiz
     */
    @Autowired
    private FamilyUserBiz userBiz;

    @Autowired
    private UserAuthUtil userAuthUtil;
    private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12);


    public AppUserInfo validate(String mobile, String password){
        AppUserInfo info = new AppUserInfo();
        userBiz.deluser(mobile);
        FamilyUser user = userBiz.getUserByMobile(mobile);
        if(user != null){
            if (encoder.matches(password, user.getPassword())) {
                BeanUtils.copyProperties(user, info);
                info.setId(user.getId());
            }
            return info;
        }else{
            return info;
        }


    }





}
